﻿Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Web.Script
Imports System.Web.Script.Services
Imports System.ComponentModel
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Json
Imports System.IO

<System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class GameService
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    <ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
    Public Function HelloWorld() As String

        Dim Test As CustomData
        Dim serializer As DataContractJsonSerializer
        Dim ms As MemoryStream
        Dim jsonString As String

        Test = New CustomData("Hello", "World")
        serializer = New DataContractJsonSerializer(Test.[GetType]())
        ms = New MemoryStream()

        serializer.WriteObject(ms, Test)
        jsonString = Encoding.[Default].GetString(ms.ToArray())

        ms.Close()

        Return jsonString

    End Function

End Class

<DataContractAttribute()>
Public Class CustomData
    <DataMemberAttribute()>
    Property Value1 As String = ""
    <DataMemberAttribute()>
    Property Value2 As String = ""

    Public Sub New(ByVal V1 As String, ByVal V2 As String)
        Value1 = V1
        Value2 = V2
    End Sub
End Class
